#!/bin/bash

if [ "$1" = "-l" ]; then
	URL='http://localhost:8080/import2/'
	shift
else
	URL='http://tppt.appspot.com/import2/'
fi

for FILE ; do
	FILE_NAME=${FILE##*/}
	PROBLEM=`echo $FILE_NAME|sed 's/\..*$//'`
	TIME_FILE=results/$FILE_NAME.time
	OUT_FILE=results/$FILE_NAME.txt
	SUBMIT_RESULT_FILE=results/$FILE_NAME.submit_result.html

	echo 'Proving ' $FILE
	(time -p ./sine $FILE 2>/dev/null) >$OUT_FILE 2>$TIME_FILE

	TIME=`grep user $TIME_FILE|sed 's/user //'`

	if grep ' PROVED ---' $OUT_FILE >/dev/null; then
		RESULT='Proved'
	elif grep ' CANNOT PROVE ---' $OUT_FILE >/dev/null; then
		RESULT='TimeOut'
	else
		RESULT='Unknown'
	fi
	echo "$PROBLEM finished with result $RESULT in $TIME"
	curl -F "data=@-" $URL >$SUBMIT_RESULT_FILE <<EOF
Result
problem	prover	resultType	computer	time
$PROBLEM	sine0def	$RESULT	pcms	$TIME
EOF

done;
